package com.example.controller.aboutUser;

import com.example.vo.request.CreateRoleForm;
import com.example.vo.request.EditRoleDesForm;
import com.example.vo.request.NewRolePermission;
import com.example.permission.PermissionCheck;
import com.example.service.aboutUser.RoleService;
import com.example.vo.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/role")
@CrossOrigin
public class RoleController {

    @Resource
    private RoleService roleService;

    @GetMapping("/allRole")
    public Result getAllRole() {
        return roleService.getAllRole();
    }

    @PostMapping("/createRole")
    @PermissionCheck(permissionPath = "/systemManagement/roleManagement/createRole")
    public Result createRole(@RequestBody CreateRoleForm createRoleForm) {
        return roleService.createRole(createRoleForm);
    }

    @GetMapping("/getPermissionsByRoleId/{roleId}")
    public Result getPermissionsByRoleId(@PathVariable Integer roleId) {
        return roleService.getPermissionsByRoleId(roleId);
    }

    @PostMapping("/updateRolePermission")
    @PermissionCheck(permissionPath = "/systemManagement/roleManagement/operateRole")
    public Result updateRolePermission(@RequestBody NewRolePermission newRolePermission) {
        return roleService.updateRolePermission(newRolePermission);
    }

    @PostMapping("/updateRoleDescription")
    @PermissionCheck(permissionPath = "/systemManagement/roleManagement/operateRole")
    public Result updateRoleDescription(@RequestBody EditRoleDesForm editRoleDesForm) {
        return roleService.updateRoleDescription(editRoleDesForm);
    }
}
